package com.ljfiction.book.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ljfiction.book.R;
import com.ljfiction.book.fragment.ranking.RankingFrament;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2017/7/6.
 */

public class HomRankingLiftAdapter extends BaseAdapter {
    private List<String> datas;
    public static int mPosition;

    public HomRankingLiftAdapter(List<String> datas) {
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LeftListView leftListView=null;
        if (convertView==null){
            leftListView=new LeftListView();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.leftlistview_homranking, null);
            x.view().inject(leftListView,convertView);
            convertView.setTag(leftListView);
        }else {
            leftListView= (LeftListView) convertView.getTag();
        }


        mPosition = position;
        leftListView.textView.setText(datas.get(position));
        if (position == RankingFrament.mPosition) {
            convertView.setBackgroundColor(Color.parseColor("#f77583"));
            leftListView.textView.setTextColor(Color.parseColor("#ffffff"));
        } else {
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));
            leftListView.textView.setTextColor(Color.parseColor("#333333"));
        }
        return convertView;
    }

    @ContentView(R.layout.leftlistview_homranking)
    public class LeftListView {
        @ViewInject(R.id.leftlistviewtext)
        TextView textView;

    }
}
